import yaml

def convert_2_crontab(src, dst):
    with open(src, "r", encoding='utf-8') as f:
        text = f.read()
        data = yaml.load(text, yaml.FullLoader)
        events = data['inputs']['events']
    task = []
    with open(dst, "w+") as cronlist:
        for event in events:
            if event['timer']['parameters']['enable']:
                task_timer = event['timer']['parameters']['cronExpression']
                task_id = event['timer']['parameters']['argument']
                task.extend(["%s bash jd.sh %s.js\n" %(task_timer, id)for id in task_id.split("&")])
        cronlist.writelines(task)

if __name__ == "__main__":
    convert_2_crontab(r'/jd/jdTool/serverless.yml', r"/jd/config/crontab.list")
